package com.windaka.elements.controller;


import com.windaka.elements.annotation.RepeatSubmit;
import com.windaka.elements.model.dto.LoginDTO;
import com.windaka.elements.model.vo.LoginImageVO;
import com.windaka.elements.model.vo.LoginVO;
import com.windaka.elements.utils.DtoCheckUtils;
import com.windaka.elements.utils.Ret;
import com.windaka.elements.annotation.Render;
import com.windaka.elements.exception.BaseException;
import com.windaka.elements.service.OauthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 权限相关
 * @author song
 * @date 16:15 2022/8/17
**/
@Api(tags = "权限相关")
@RestController
@RequestMapping("/Oauth")
@RequiredArgsConstructor
public class OauthController {

    private final OauthService oauthServiceImpl;

    /**
    * 获取验证码
    * @author song
    * @date 2025/6/15 18:10
    */
    @ApiOperation(value = "获取验证码")
    @Render
    @GetMapping("/getImageCode")
    public Ret<LoginImageVO> getImageCode() throws BaseException {
        return Ret.data(oauthServiceImpl.getImageCode());
    }

    /**
     * 登录接口
     * @author song
     * @date 16:44 2022/8/17
     * @param loginDTO 登录参数
    **/
    @ApiOperation(value = "用户登录")
    @Render
    @RepeatSubmit(interval = 1000)
    @PostMapping("/login")
    public Ret<LoginVO> getAutoTest(@RequestBody LoginDTO loginDTO) throws BaseException {
        DtoCheckUtils.check(loginDTO);
        return Ret.data(oauthServiceImpl.login(loginDTO));
    }

    /**
     * 退出登录
     * @author song
     * @date 11:31 2022/8/18
     * @return String 结果
    **/
    @ApiOperation(value = "退出登录")
    @Render
    @GetMapping("/loginOut")
    public Ret<String> loginOut() {
        return Ret.data("退出成功");
    }
}
